package com.kuangjia.student_ems.repository;

import com.kuangjia.student_ems.entity.Position;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PositionRepository extends JpaRepository<Position, Long> {
    
    List<Position> findByDepartmentId(Long departmentId);
    
    List<Position> findByDepartmentIdAndStatus(Long departmentId, Boolean status);
    
    List<Position> findByStatus(Boolean status);
    
    boolean existsByNameAndDepartmentId(String name, Long departmentId);
    
    boolean existsByNameAndDepartmentIdAndIdNot(String name, Long departmentId, Long id);
    
    @Query("SELECT p FROM Position p JOIN FETCH p.department d WHERE LOWER(p.name) LIKE LOWER(:keyword) OR LOWER(p.description) LIKE LOWER(:keyword) OR LOWER(d.name) LIKE LOWER(:keyword)")
    List<Position> searchPositions(@Param("keyword") String keyword);
} 